home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / gnu / autoconf.lha / autoconf-1.4 / autoheader.sh < prev    next >
Linux/UNIX/POSIX Shell Script  |  1993-05-15  |  5KB  |  174 lines

  1. #!/bin/sh
  2. # autoheader -- create `config.h.in' from `configure.in'
  3. # Copyright (C) 1992, 1993 Free Software Foundation, Inc.
  4.  
  5. # This program is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation; either version 2, or (at your option)
  8. # any later version.
  9.  
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. # GNU General Public License for more details.
  14.  
  15. # You should have received a copy of the GNU General Public License
  16. # along with this program; if not, write to the Free Software
  17. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  
  19. # Written by Roland McGrath.
  20.  
  21. # If given no args, create `config.h.in' from template file `configure.in'.
  22. # With one arg, create a header file on standard output from
  23. # the given template file.
  24.  
  25. usage="Usage: autoheader [-h] [--help] [-m dir] [--macrodir=dir] 
  26.                   [-v] [--version] [template-file]" 
  27.  
  28. test -z "${AC_MACRODIR}" && AC_MACRODIR=@datadir@
  29. test -z "${M4}" && M4=@M4@
  30.  
  31. print_version=""
  32. while test $# -gt 0 ; do
  33.    case "z${1}" in 
  34.       z-h | z--help | z--h* )
  35.          echo "${usage}" 1>&2; exit 1 ;;
  36.       z--macrodir=* | z--m*=* )
  37.          AC_MACRODIR="`echo \"${1}\" | sed -e 's/^[^=]*=//'`"
  38.          shift ;;
  39.       z-m | z--macrodir | z--m* ) 
  40.          shift
  41.          test $# -eq 0 && { echo "${usage}" 1>&2; exit 1; }
  42.          AC_MACRODIR="${1}"
  43.          shift ;;
  44.       z-v | z--version | z--v* )
  45.          print_version="-DAC_PRINT_VERSION"
  46.          shift ;;
  47.       z-- )     # Stop option processing
  48.         shift; break ;;
  49.       z- )    # Use stdin as input.
  50.         break ;;
  51.       z-* )
  52.         echo "${usage}" 1>&2; exit 1 ;;
  53.       * )
  54.         break ;;
  55.    esac
  56. done
  57.  
  58. # Needed for some versions of `tr' so that character classes in `[]' work.
  59. if test "${LANG+set}" = "set" ; then
  60.    LANG=C
  61. fi
  62.  
  63. TEMPLATES="${AC_MACRODIR}/acconfig.h"
  64. test -r acconfig.h && TEMPLATES="${TEMPLATES} acconfig.h"
  65. MACROFILES="${AC_MACRODIR}/acgeneral.m4 ${AC_MACRODIR}/acspecific.m4"
  66. test -r ${AC_MACRODIR}/aclocal.m4 \
  67.    && MACROFILES="${MACROFILES} ${AC_MACRODIR}/aclocal.m4"
  68. test -r aclocal.m4 && MACROFILES="${MACROFILES} aclocal.m4"
  69. MACROFILES="${print_version} ${MACROFILES}"
  70.  
  71. case $# in
  72.   0) infile=configure.in ;;
  73.   1) infile=$1 ;;
  74.   *) echo "$usage" >&2; exit 1 ;;
  75. esac
  76.  
  77. # These are the alternate definitions of the acgeneral.m4 macros we want to
  78. # redefine.  They produce strings in the output marked with "@@@" so we can
  79. # easily extract the information we want.
  80. frob='define([AC_DEFINE],[
  81. @@@syms="$syms $1"@@@
  82. ])dnl
  83. define([AC_HAVE_FUNCS],[
  84. @@@funcs="$funcs $1"@@@
  85. ])dnl
  86. define([AC_HAVE_HEADERS],[
  87. @@@headers="$headers $1"@@@
  88. ])dnl'
  89.  
  90. # We extract assignments of SYMS, FUNCS, and HEADERS from the modified
  91. # autoconf processing of the input file.
  92. # Traditional sed mishandles /p1/,/p2/ construct if both patterns
  93. # appear on the same line (junio@twinsun.com).
  94. eval "`echo \"$frob\" \
  95.        | $M4 $MACROFILES - $infile \
  96.        | sed -n -e '
  97.         : again
  98.         /^@@@.*@@@$/s/@@@\(.*\)@@@$/\1/p
  99.         /^@@@/{
  100.             s/^@@@//p
  101.             n
  102.             s/^/@@@/
  103.             b again
  104.         }'`"
  105.  
  106. # Make SYMS newline-separated rather than blank-separated.
  107. syms="`for sym in $syms; do echo $sym; done`"
  108.  
  109. if test $# -eq 0; then
  110.   tmpout=autoh$$
  111.   trap "rm -f $tmpout; exit 1" 1 3 15
  112.   exec > $tmpout
  113. fi
  114.  
  115. echo "/* Generated automatically from $infile by autoheader.  DO NOT EDIT!  */"
  116.  
  117. # This puts each paragraph on its own line, separated by @s.
  118. if test -n "$syms"; then
  119.    # Make sure the boundary of template files is also the boundary
  120.    # of the paragraph.  Extra newlines don't hurt since they will
  121.    # be removed.
  122.    for t in $TEMPLATES; do cat $t; echo; echo; done |
  123.    # The sed script is suboptimal because it has to take care of
  124.    # some broken sed (e.g. AIX) that remove '\n' from the
  125.    # pattern/hold space if the line is empty. (junio@twinsun.com).
  126.    sed -n -e '
  127.     /^[     ]*$/{
  128.         x
  129.         s/\n/@/g
  130.         p
  131.         s/.*/@/
  132.         x
  133.     }
  134.     H' | sed -e 's/@@*/@/g' |
  135.    # Select each paragraph that refers to a symbol we picked out above.
  136.    fgrep "$syms" |
  137.    tr @ \\012
  138. fi
  139.  
  140. for func in $funcs; do
  141.   sym="`echo ${func} | sed 's/[^a-zA-Z0-9_]/_/g' | tr '[a-z]' '[A-Z]'`"
  142.   echo "
  143. /* Define if you have ${func}.  */
  144. #undef HAVE_${sym}"
  145. done
  146.  
  147. for header in $headers; do
  148.   sym="`echo ${header} | sed 's/[^a-zA-Z0-9_]/_/g' | tr '[a-z]' '[A-Z]'`"
  149.   echo "
  150. /* Define if you have the <${header}> header file.  */
  151. #undef HAVE_${sym}"
  152. done
  153.  
  154. status=0
  155.  
  156. for sym in $syms; do
  157.   if fgrep $sym $TEMPLATES >/dev/null; then
  158.     : # All is well.
  159.   else
  160.     echo "$0: Symbol \`${sym}' is not covered by $TEMPLATES" >&2
  161.     status=1
  162.   fi
  163. done
  164.  
  165. if test $# -eq 0; then
  166.   if test $status -eq 0; then
  167.     mv -f $tmpout config.h.in
  168.   else
  169.     rm -f $tmpout
  170.   fi
  171. fi
  172.  
  173. exit $status
  174.